package com.bookstore.dao.impl;

import com.bookstore.dao.BaseDao;
import com.bookstore.dao.OrderDao;
import com.bookstore.entity.Order;
import com.bookstore.entity.User;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao{

    @Override
    public int insertOrder(Order order) {
        String sql="insert into t_order(money,receiverAddress,receiverName,receiverPhone,paystate,ordertime,user_id) values(?,?,?,?,?,?,?)";
        return super.update(sql,order.getMoney(),order.getReceiverAddress(),order.getReceiverName(),order.getReceiverPhone(),order.getPaystate(),order.getOrdertime(),order.getUser_id());
    }

    @Override
    public int updateOrder(Order order) {
        String sql="update t_order money=?,receiverAddress=?,receiverName=?,receiverPhone=?,paystate=?,ordertime=?,user_id=? where id=?";
        return super.update(sql,order.getMoney(),order.getReceiverAddress(),order.getReceiverName(),order.getReceiverPhone(),order.getPaystate(),order.getOrdertime(),order.getUser_id(),order.getId());
    }

    @Override
    public int deleteOrder(int orderId) {
        String sql="delete from t_order where id=?";
        return super.update(sql,orderId);
    }

    @Override
    public List<Order> queryAllOrder() {
        String sql="select * from t_order";
        return super.queryMore(Order.class,sql);
    }

    @Override
    public Order queryOrderId(int orderId) {
        String sql="select * from t_order where id=?";
        return super.queryOne(Order.class,sql,orderId);
    }
}
